import 'package:flutter/material.dart';
import 'package:jiffy/jiffy.dart';
import 'package:safetymonitor/app/components/custom_app_bar.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_file_upload_page.dart';
import 'package:safetymonitor/app/components/custom_modele/custom_title_chart_page.dart';
import 'package:safetymonitor/app/data/entities/home/enterprise/enterprise_emergency_plan_entity_entity.dart';
import 'package:safetymonitor/app/data/entities/home/enterprise/enterprise_staff_entity_entity.dart';

import '../../../../app/core/core.dart';

/// 一企一档-应急预案-详情
class EmergencyDetails extends StatefulWidget {
  const EmergencyDetails({super.key});

  @override
  State<EmergencyDetails> createState() => _EmergencyDetailsState();
}

class _EmergencyDetailsState extends State<EmergencyDetails> {
  @override
  Widget build(BuildContext context) {
    final EnterpriseEmergencyPlanEntityEntity item = Get.arguments as EnterpriseEmergencyPlanEntityEntity;
    return Scaffold(
      appBar: CustomAppBar(
        titleText: '应急预案详情',
      ),
      body: Column(
        children: [
          CustomTitleChartPage(
            title: item.planName,
            child: itemWeight(item),
          )
        ],
      ),
    );
  }

  Widget _title(String title, String? value) {
    return Row(
      children: [
        Text(
          '$title：',
          style: TextStyle(
            fontSize: 14.sp,
            fontWeight: FontWeight.w400,
            color: const Color(0xFFC7CEE5),
          ),
        ),
        Expanded(
          child: Align(
            alignment: Alignment.centerLeft,
            child: Text(
              value ?? '空',
              style: TextStyle(
                fontSize: 14.sp,
                fontWeight: FontWeight.w400,
                color: const Color(0xFF1D3452),
              ),
            ),
          ),
        ),
      ],
    );
  }

  Widget itemWeight(EnterpriseEmergencyPlanEntityEntity item) {
    //对象
    return Column(
      children: [
        _title('预案类别', item.planTypeName),
         AppGaps.vGap8,
         _title('预案编号', item.planCode),
        AppGaps.vGap8,
        _title('编制单位', item.planCompany),
        AppGaps.vGap8,
        _title('适用事故等级', item.levelName??''),
        AppGaps.vGap8,
        _title('编制人', item.planPerson),
        AppGaps.vGap8,
        _title('事故原因', item.reasonTypeName),
        AppGaps.vGap8,
        _title('预案类型', item.planType),
        AppGaps.vGap8,
        _title('编制时间', int.parse( item.planTime ?? '0')!=0?Jiffy.parseFromMillisecondsSinceEpoch(int.parse( item.planTime ?? '0')).format(pattern: 'yyyy-MM-dd HH:mm:ss'):'',),
        AppGaps.vGap8,
        CustomFileUploadPage(title: '附件', isRequired: false,isEnabled: false,uploadedFiles: [item.fileUrl ?? ''], onCallBack: (p0){},)
      ],
    );
  }

}
